<?php
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
if($_RQ['op']=='list'){
	$pindex = max(1, intval($_SESSION['page']));
	$psize = 10;
	$params=array('uniacid'=>$_SESSION['uniacid']);
    $fields=array('id','title','status','goodsid');
    $orderby='id desc';
	$total='';
	$return['list']=pdo_getslice('jy_weishop_fullback_goods',$params,array($pindex,$psize),$total,$fields,'',$orderby);
	
	foreach($return['list'] as &$v){
		$v['image']=pdo_getcolumn('jy_weishop_goods',array('id'=>$v['goodsid']),'image');
		
	}
	$return['status']=array('0'=>'关闭','1'=>'开启');
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'全返管理'),
			array('op'=>'edit','title'=>'添加商品'),
		),
		'list'=>array('data'=>'list','list'=>array(
			array('name'=>'title','title'=>'标题','type'=>'string'),
			array('name'=>'image','title'=>'商品图片','type'=>'image'),
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status'),			
		)),
	);
	$return['htmls']=$htmls;
	
	exi($return);
	}
	if($_RQ['op']=='edit'){
	$id=intval($_RQ['id']);
	if($id){
	$item=pdo_get('jy_weishop_fullback_goods',array('id'=>$id));
	
	}else{
		$item=array();
	}
    $return['item']=$item;
	$return['status']=array('0'=>'关闭','1'=>'开启');
	$return['type']=array('0'=>'指定金额','1'=>'指定比例');
	$return['refund']=array('0'=>'不支持','1'=>'支持');
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'desc'=>'赠品设置',
		'tabs'=>array(
			array('op'=>'list','title'=>'赠品管理'),
			array('op'=>'edit','title'=>'添加赠品'),
		),
		'edit'=>array(
			array('name'=>'paixu','title'=>'排序','type'=>'string'),
			array('name'=>'title','title'=>'标题','type'=>'string'),			
			
			array('name'=>'type','title'=>'全返类型','type'=>'radio','options'=>'type','help'=>''),
			array('name'=>'fullbackprice','title'=>'全返金额','type'=>'string','show'=>array('type'=>0)),
			array('name'=>'fullbackratio','title'=>'全返比例(%)','type'=>'string','show'=>array('type'=>1)),
			array('type'=>'choose','title'=>'选择商品','name'=>'goodsid','action'=>'sale.get_good','choose_title'=>'选择商品'),
						
			array('name'=>'day','title'=>'全返时间(确认收货后多少天开始全返)','type'=>'string','help'=>'全返的时间尽量设置超过系统允许【确认收货】->【申请退款】的时间'),
			array('name'=>'refund','title'=>'全返开始后支持退款','type'=>'radio','options'=>'refund'),	
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status'),	
			
			)
			);
	$return['htmls']=$htmls;
	exi($return);
	}
	if($_RQ['op']=='post'){
	$postdata=get_postdata();
	$data=array_fields(array('title','status','paixu','goodsid','type','fullbackprice','fullbackratio','day','refund'),$postdata);
	
	$id=intval($postdata['id']);
			if($id){
				pdo_update('jy_weishop_fullback_goods',$data,array('id'=>$id));
				exi('设置成功！','','list');
			}else{
			    $data['uniacid']=$_SESSION['uniacid'];
				pdo_insert('jy_weishop_fullback_goods',$data);
				exi('添加成功！','','list');
			}
			}
			if($_RQ['op']=='del'){

	$id=intval($_RQ['id']);
	if($id){
		pdo_delete('jy_weishop_fullback_goods',array('id'=>$id));	
	}
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
		foreach($del as $id){
			$id=intval($id);
			if($id){
				pdo_delete('jy_weishop_fullback_goods',array('id'=>$id));
			}
		}
	}
	exi('删除成功！');
}
?>